package com.itjason.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.itjason.po.GameOption;
import com.itjason.po.OptionItem;
import com.itjason.service.OptionItemService;
import com.itjason.mapper.OptionItemMapper;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
* @author dengxiang
* @description 针对表【option_item】的数据库操作Service实现
* @createDate 2024-05-30 23:38:50
*/
@Service
public class OptionItemServiceImpl extends ServiceImpl<OptionItemMapper, OptionItem>
    implements OptionItemService{

    @Resource
    private OptionItemMapper optionItemMapper;

    @Override
    public List<OptionItem> getOptions(Integer id) {

        LambdaQueryWrapper<OptionItem> queryWrapper=new LambdaQueryWrapper<>();
        queryWrapper.eq(OptionItem::getGameId,id);

        return optionItemMapper.selectList(queryWrapper);
    }

    @Override
    public List<OptionItem> queryOptionItem(Integer id) {
        Map<String,Object> map=new HashMap<>();
        map.put("game_id",id);
        List<OptionItem> optionItems = optionItemMapper.selectByMap(map);
        return optionItems;
    }

    @Override
    public int saveOptionItem(List<OptionItem> saveOptionItems) {

        return optionItemMapper.saveOptionItems(saveOptionItems);
    }

    @Override
    public int delete(Integer id) {
        LambdaQueryWrapper<OptionItem> queryWrapper=new LambdaQueryWrapper<>();
        queryWrapper.eq(OptionItem::getGameId,id);
        return optionItemMapper.delete(queryWrapper);
    }

    @Override
    public int updateOptionItems(List<OptionItem> optionItems) {
        for (OptionItem optionItem : optionItems) {
           optionItemMapper.updateById(optionItem);
        }
        return 0;
    }
}




